package com.purang.web.entity.domain;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;

import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 基本DO
 *
 * @author Chuan Qin
 * @version 1.0-RELEASE
 * @since 1.0-RELEASE
 */
public interface BaseDo {

    SimpleDateFormat FMT_DATE = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat FMT_DATE_ = new SimpleDateFormat("yyyyMMdd");
    SimpleDateFormat FMT_MINUTE = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    SimpleDateFormat FMT_SECOND = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    SimpleDateFormat FMT_SSS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
    SimpleDateFormat FMT_MONTH = new SimpleDateFormat("yyyy-MM");
    SimpleDateFormat FMT_SECOND_INT = new SimpleDateFormat("yyyyMMddHHmmss");

    default BigInteger createId() {
        return new BigInteger(String.valueOf(IdWorker.getId()));
    }

    default String createTime(SimpleDateFormat dateFormat) {
        return dateFormat.format(new Date());
    }

    default long createTimeLong(SimpleDateFormat dateFormat) {
        return Long.valueOf(createTime(dateFormat));
    }

    default BigInteger createTimeBigInteger(SimpleDateFormat dateFormat) {
        return new BigInteger(createTime(dateFormat));
    }

    default void selectPage(QueryWrapper queryWrapper, Long pageNum, Long pageSize) {
        pageNum = (pageNum - 1) * pageSize;
        queryWrapper.last(" LIMIT " + pageNum + "," + pageSize);
    }
}
